package cn.com.lyj6851.modules.product.controller;

import cn.com.lyj6851.enums.ShopCommonEnum;
import cn.com.lyj6851.logging.aop.AopLog;
import cn.com.lyj6851.modules.product.domain.YdyStoreProductReply;
import cn.com.lyj6851.modules.product.service.YdyStoreProductReplyService;
import cn.com.lyj6851.modules.product.service.dto.YdyStoreProductReplyQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
* @author hupeng
* @date 2019-11-03
*/
@Api(tags = "商城:评论管理")
@RestController
@RequestMapping("api")
public class StoreProductReplyController {


    private final YdyStoreProductReplyService yxStoreProductReplyService;

    public StoreProductReplyController(YdyStoreProductReplyService yxStoreProductReplyService) {
        this.yxStoreProductReplyService = yxStoreProductReplyService;
    }

    @AopLog("查询")
    @ApiOperation(value = "查询")
    @GetMapping(value = "/ydyStoreProductReply")
    @PreAuthorize("hasAnyRole('admin','STOREPRODUCTREPLY_ALL','STOREPRODUCTREPLY_SELECT')")
    public ResponseEntity getYdyStoreProductReplys(YdyStoreProductReplyQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(yxStoreProductReplyService.queryAll(criteria,pageable),HttpStatus.OK);
    }



    @AopLog("修改")
    @ApiOperation(value = "修改")
    @PutMapping(value = "/ydyStoreProductReply")
    @PreAuthorize("hasAnyRole('admin','STOREPRODUCTREPLY_ALL','STOREPRODUCTREPLY_EDIT')")
    public ResponseEntity update(@Validated @RequestBody YdyStoreProductReply resources){
        resources.setMerchantReplyTime(new Date());
        resources.setIsReply(ShopCommonEnum.REPLY_1.getValue());
        yxStoreProductReplyService.updateById(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @AopLog("删除")
    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/ydyStoreProductReply/{id}")
    @PreAuthorize("hasAnyRole('admin','STOREPRODUCTREPLY_ALL','STOREPRODUCTREPLY_DELETE')")
    public ResponseEntity delete(@PathVariable Long id){
        yxStoreProductReplyService.removeById(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
